#coding: utf-8
import json
import io
import sys

# 执行方式 python test.py 2 3   
# themeIndex 皮肤列表的position
# appIndex 应用列表的position

themeIndex = sys.argv[1];
# print 'themeIndex:', themeIndex
themeList = [
	["xxwbaby", "金职托育通"],
	["xm", "奈思托育星"],
	["xybaby", "星越宝贝"],
	["jzwy", "金职托育通"]
]

themeReplace = themeList[int(themeIndex)];

# 修改 App.vue
with io.open('./App.vue', 'r', encoding='UTF-8') as fp:
    jsonStr = fp.read();

for theme in themeList:
	jsonStr = jsonStr.replace("channel: '%s',"%theme[0], "channel: '%s',"%themeReplace[0])

# print(jsonStr)

with open("./App.vue", "wb") as fp:
    fp.write(jsonStr.encode("utf-8"))
	
	
# 修改 pages.json
with io.open('./pages.json', 'r', encoding='UTF-8') as fp:
    jsonStr = fp.read();
pages = json.loads(jsonStr)

navigationBarTitleText = themeReplace[1]

pages["globalStyle"]["navigationBarTitleText"] = navigationBarTitleText

with open("./pages.json", "wb") as fp:
    fp.write(json.dumps(pages, indent=4, ensure_ascii=False).encode("utf-8"))



# 修改 manifest.json
with io.open('./manifest.json', 'r' ,encoding='UTF-8') as fp:
    manifestStr = fp.read();
manifest = json.loads(manifestStr)

description = themeReplace[1]
manifest["name"] = description

with open("./manifest.json", "wb") as fp:
    fp.write(json.dumps(manifest, indent=4, ensure_ascii=False).encode("utf-8"))